package logic

import (
	"context"
	"database/sql"
	"github.com/zeromicro/go-zero/core/logx"
	"goods/goods"
	"goods/internal/model"
	"goods/internal/svc"
)

type UpdateGoodsSkuLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateGoodsSkuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGoodsSkuLogic {
	return &UpdateGoodsSkuLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateGoodsSkuLogic) UpdateGoodsSku(in *goods.UpdateGoodsSkuRequest) (*goods.UpdateGoodsSkuResponse, error) {
	// todo: add your logic here and delete this line
	goodsSku := &model.GoodsSku{
		DishId: in.Data.DishId,
		Name:   sql.NullString{String: in.Data.Name, Valid: true},
		Value:  sql.NullString{String: in.Data.Value, Valid: true},
	}
	err := l.svcCtx.GoodsSku.Update(context.Background(), goodsSku)
	if err != nil {
		return &goods.UpdateGoodsSkuResponse{Code: -1, Msg: "失败的更新"}, err
	}
	return &goods.UpdateGoodsSkuResponse{Code: 200, Msg: "更新成功"}, nil
}
